package com.zw.yzk.kabu.data.repository;

import com.zw.yzk.kabu.data.network.task.Task;
import com.zw.yzk.kabu.data.network.ServiceGenerator;
import com.zw.yzk.kabu.data.network.entity.UploadImageTokenEntity;
import com.zw.yzk.kabu.data.network.service.UploadImageTokenService;

import javax.inject.Inject;

import rx.Observable;
import rx.functions.Func1;

/**
 * Created by zhanwei on 2016/12/24.
 */

public class GetUploadImageTokenRepository extends CommonRepository {

    @Inject
    public GetUploadImageTokenRepository() {
    }

    @Override
    protected Observable connectServer(Task task) {
        UploadImageTokenService service = ServiceGenerator.createService(UploadImageTokenService.class);
        return service.getUploadToken(task.userId, task.accessToken);
    }

    @Override
    protected Func1<UploadImageTokenEntity, Observable> getServerData() {
        return new Func1<UploadImageTokenEntity, Observable>() {
            @Override
            public Observable call(UploadImageTokenEntity entity) {
                return Observable.just(entity.result.token);
            }
        };
    }

}
